import Vue from 'vue'
import Vuex from 'vuex'
import menu from './modules/menu'
import role from './modules/role'
import user from './modules/user'
import cate from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import banner from './modules/banner'
import seck from './modules/seck'
import member from './modules/member'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userinfo: sessionStorage.getItem("userinfo") ?
      JSON.parse(sessionStorage.getItem("userinfo")) :
      null,
  },
  getters:{
     getUser(state){
       return state.userinfo;
     }
  },
  mutations:{
    REQ_USER(state,payload){
      if(payload){
        state.userinfo = payload,
        sessionStorage.setItem('userinfo',JSON.stringify(payload))
      }else{
        sessionStorage.removeItem("userinfo");
      }
    }
  },
  actions:{
    changeUserAction({commit},payload){
      commit("REQ_USER",payload)
    }
  },
  modules: {
    menu,
    role,
    user,
    cate,
    specs,
    goods,
    banner,
    seck,
    member
  }
})